package com.aiti.lulian.controller;

import cn.hutool.core.exceptions.ExceptionUtil;
import com.aiti.base.core.base.controller.WebController;
import com.aiti.base.core.exception.BusinessException;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.bo.YunZhanTingEnterpriseHistoryRequest;
import com.aiti.lulian.dto.OcrBusinessLicenseDto;
import com.aiti.lulian.dto.RegisterEnterpriseInfoDto;
import com.aiti.lulian.service.EnterpriseInfoManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * description:
 * auth fcb
 * date 2025-04-24 09:53
 **/
@RestController
@RequestMapping("/enterpriseManage")
@Slf4j
@Api(tags = "云展厅企业注册")
public class EnterpriseManageController extends WebController {

    @Autowired
    private EnterpriseInfoManageService enterpriseInfoManageService;

    @PostMapping("/enterpriseRegister")
    public Message yunZhanTingEnterpriseHistory(@RequestBody RegisterEnterpriseInfoDto dto){
        try {
            enterpriseInfoManageService.registerEnterpriseInfo(dto);
        }catch (Exception e) {
            log.error("注册时填写企业信息异常：{}", ExceptionUtil.stacktraceToString(e));
            return Fail(e.getMessage());
        }

        return Success();
    }

    @PostMapping("/checkBusinessLicense")
    @ApiOperation(value = "OCR营业执照信息校验")
    public Message checkBusinessLicense(@RequestBody OcrBusinessLicenseDto dto){
        try {
            enterpriseInfoManageService.checkBusinessLicense(dto);
        }catch (Exception e) {
            if(e instanceof BusinessException) {
                return Fail(e.getMessage());
            }
            return Fail("接口异常");
        }
        return Success();
    }

}
